package com.example.redis.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.example.redis.enums.ResultCode.FAIL;
import static com.example.redis.enums.ResultCode.SUCCESS;


/**
 * 工具类，用于包装获取到的data
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code; //StatusCode
    private Boolean success;

    private T data; //查询到的结果
    private String msg; //信息

    public static<T> Result<T> ok(T data){
        return new Result<>(SUCCESS.code, true, data, "success");
    }
    public static<T> Result<T> fail(String msg){
        return new Result<>(FAIL.code, false, null, msg);
    }

}
